<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
          <!-- {required: true, message:'图片路径不能为空', trigger:'blur'} -->
            <el-form-item label="照片" prop="photo"
                :rules="[
                 ]">
              <el-upload ref="photo"
              v-if="visible"
              list-type="picture-card"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/peopleinformation/basicdata/peopleInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {
                        $alert(`<img style='width:100%' src=' ${(file.response && file.response.url) || file.url}'/>`,  {
                          dangerouslyUseHTMLString: true,
                          showConfirmButton: false,
                          closeOnClickModal: true,
                          customClass: 'showPic'
                        });
                    }"
                    :on-success="(response, file, fileList) => {
                       inputForm.photo = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.photo = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="1"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="picArra">
                    <i class="el-icon-plus"></i>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位" prop="oneInstitutional"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.oneInstitutional" placeholder="请填写一级机构名称"     ></el-input> -->
              <el-select v-model="inputForm.oneInstitutional" filterable placeholder="请填写单位" style="width:100%;" >
                <el-option v-for="item in oneInstitutionalArr" @click.native="searchTwoInstitutionalName(item)" :label="item.organization" :value="item.organization" :key="item.organization"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="正处级领导职数" prop="zhengLeaderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.zhengLeaderNumber" placeholder="请填写正处级领导职数" ></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="副处级领导职数" prop="fuLeaderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.fuLeaderNumber" placeholder="请填写副处级领导职数" ></el-input>
            </el-form-item>
        </el-col>
      <el-col :span="12">
          <el-form-item label="岗位现状(正处)" prop="oneJobStatus"
              :rules="[
               ]">
            <el-input v-model="inputForm.oneJobStatus" placeholder="请填写岗位现状(正处)" ></el-input>
          </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="岗位现状(副处)" prop="heightEducation"
              :rules="[
               ]">
            <el-input v-model="inputForm.heightEducation" placeholder="请填写岗位现状(副处)"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="科室名称" prop="twoInstitutionalName"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.twoInstitutionalName" placeholder="请填写二级机构名称"     ></el-input> -->
            <el-select v-model="inputForm.twoInstitutionalName" filterable placeholder="请填写科室名称" style="width:100%;" >
              <el-option v-for="item in twoInstitutionalNameArr" :label="item.organization" :value="item.organization" :key="item.id"></el-option>
            </el-select>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="科级领导职数" prop="keLeaderNumber"
              :rules="[
               ]">
            <el-input v-model="inputForm.keLeaderNumber" placeholder="请填写科级领导职数" ></el-input>
          </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="岗位现状(正科)" prop="twoJobStatus"
              :rules="[
               ]">
            <el-input v-model="inputForm.twoJobStatus" placeholder="请填写岗位现状(正科)" ></el-input>
          </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="岗位现状(副科)" prop="oneEducation"
              :rules="[
               ]">
            <el-input v-model="inputForm.oneEducation" placeholder="请填写岗位现状(副科)"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="员工编号" prop="workNumber"
              :rules="[
               ]">
          <el-input v-model="inputForm.workNumber" placeholder="请填写员工编号"     ></el-input>
          </el-form-item>
        </el-col>
      <el-col :span="12">
          <el-form-item label="姓名" prop="name"
              :rules="[
               ]">
            <el-input v-model="inputForm.name" placeholder="请填写姓名"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="性别" prop="gender"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.gender" placeholder="请填写性别"     ></el-input> -->
            <el-select v-model="inputForm.gender" placeholder="请填写性别" style="width:100%;" >
              <el-option v-for="item in $dictUtils.getDictList('gender')" :label="item.label" :value="item.value" :key="item.value"></el-option>
            </el-select>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="民族" prop="national"
              :rules="[
               ]">
            <el-input v-model="inputForm.national" placeholder="请填写民族"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="出生年月" prop="born"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.born" placeholder="请填写出生年月"     ></el-input> -->
            <el-date-picker
                  value-format="yyyy.MM.dd"
                  v-model="inputForm.born"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;">
                </el-date-picker>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="年龄" prop="age"
              :rules="[
               ]">
            <el-input v-model="inputForm.age" disabled="disabled" placeholder="请填写年龄"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="现任职务(文件)" prop="currentPositionFile"
              :rules="[
               ]">
            <el-input v-model="inputForm.currentPositionFile" placeholder="请填写现任职务(文件)"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="现任职务(校内)" prop="currentPosition"
              :rules="[
               ]">
            <el-input v-model="inputForm.currentPosition" placeholder="请填写现任职务"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="任职时间" prop="inOffice"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.inOffice" placeholder="请填写任职时间"     ></el-input> -->
            <el-date-picker
                     value-format="yyyy.MM.dd"
                     v-model="inputForm.inOffice"
                     type="date"
                     placeholder="选择日期"
                     style="width:100%;">
                   </el-date-picker>
            </el-form-item>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="任职时长" prop="inOfficeTime"
              :rules="[
               ]">
            <el-input v-model="inputForm.inOfficeTime" disabled="disabled" placeholder="请填写任职时长"></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="行政级别" prop="administrativeLevel"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.administrativeLevel" placeholder="请填写行政级别"     ></el-input> -->
            <el-select v-model="inputForm.administrativeLevel" placeholder="请填写行政级别" style="width:100%;" >
              <el-option v-for="item in administrativeLevelArr" :label="item.administrativeLevel" :value="item.administrativeLevel" :key="item.id"></el-option>
            </el-select>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="任级时间" prop="asClass"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.asClass" placeholder="请填写任级时间"     ></el-input> -->
            <el-date-picker
             value-format="yyyy.MM.dd"
             v-model="inputForm.asClass"
             type="date"
             placeholder="选择日期"
             style="width:100%;">
           </el-date-picker>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="任级时长" prop="asClassTime"
              :rules="[
               ]">
            <el-input v-model="inputForm.asClassTime" disabled="disabled" placeholder="请填写任级时长"></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="全日制教育学历学位" prop="degree"
              :rules="[
               ]">
            <el-input v-model="inputForm.degree" placeholder="请填写全日制教育学历学位"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="全日制教育毕业院校及专业" prop="professional"
              :rules="[
               ]">
            <el-input v-model="inputForm.professional" placeholder="请填写全日制教育毕业院校及专业"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="在职教育学历学位" prop="nowDegree"
              :rules="[
               ]">
            <el-input v-model="inputForm.nowDegree" placeholder="请填写在职教育学历学位"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="在职教育毕业专业" prop="nowProfessional"
              :rules="[
               ]">
            <el-input v-model="inputForm.nowProfessional" placeholder="请填写在职教育毕业专业"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="最高学历/学位" prop="heightRecord"
              :rules="[
               ]">
            <el-input v-model="inputForm.heightRecord" placeholder="请填写最高学历学位学历/学位"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="专业技术职务" prop="technicalPosition"
              :rules="[
               ]">
            <el-input v-model="inputForm.technicalPosition" placeholder="请填写专业技术职务"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="专业技术资格级别" prop="technicalLevel">
             <el-select v-model="inputForm.technicalLevel" placeholder="请填写专业技术资格级别" style="width:100%;" >
               <el-option v-for="item in technicalLevelArr" :label="item.label" :value="item.value" :key="item.value"></el-option>
             </el-select>
             </el-select>
          </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="参工时间" prop="workforceDate"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.workforceDate" placeholder="请填写参工时间"     ></el-input> -->
            <el-date-picker
                  value-format="yyyy.MM.dd"
                  v-model="inputForm.workforceDate"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;">
                </el-date-picker>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="工龄" prop="workYears"
              :rules="[
               ]">
            <el-input v-model="inputForm.workYears" disabled="disabled" placeholder="请填写工龄"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="入党时间" prop="inPartyDate"
              :rules="[
               ]">
            <!-- <el-input v-model="inputForm.inPartyDate" placeholder="请填写入党时间"     ></el-input> -->
            <el-date-picker
                  value-format="yyyy.MM.dd"
                  v-model="inputForm.inPartyDate"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;">
                </el-date-picker>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="党龄" prop="heightProfessionalDate"
              :rules="[
               ]">
            <el-input v-model="inputForm.heightProfessionalDate" placeholder="请填写党龄" disabled=""></el-input>
         </el-form-item>
      </el-col>
      <!-- <el-col :span="12">
          <el-form-item label="最高毕业院校及所学专业" prop="heightGraduationSchool"
              :rules="[
               ]">
            <el-input v-model="inputForm.heightGraduationSchool" placeholder="请填写最高毕业院校及所学专业"     ></el-input>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="第一学历学位原毕业时间" prop="oneProfessionalDate"
              :rules="[
               ]">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="inputForm.oneProfessionalDate"
              type="date"
              placeholder="选择日期"
              style="width:100%;">
            </el-date-picker>
         </el-form-item>
      </el-col>
      <el-col :span="12">
          <el-form-item label="第一学历学位原毕业院校及所学专业" prop="oneGraduationSchool"
              :rules="[
               ]">
            <el-input v-model="inputForm.oneGraduationSchool" placeholder="请填写第一学历学位原毕业院校及所学专业"     ></el-input>
         </el-form-item>
      </el-col> -->
      <!-- <el-col :span="12">
          <el-form-item label="考核年份" prop="assessYear"
              :rules="[
               ]">
            <el-input v-model="inputForm.assessYear" placeholder="请填写考核年份"     ></el-input>
         </el-form-item>
      </el-col> -->
      <!-- 新建表单时多加一个字段以防后期需求添加使用 -->
      <el-col :span="12">
          <el-form-item label="备注信息" prop="remarks"
              :rules="[
               ]">
        <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
          </el-form-item>
      </el-col>
        <el-col :span="12">
            <el-form-item label="岗位性质" prop="jobNature"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.jobNature" placeholder="请填写岗位性质"     ></el-input> -->
              <el-select v-model="inputForm.jobNature" placeholder="请填写岗位性质" style="width:100%;" >
                <el-option v-for="item in jobNatureArr" :label="item" :value="item" :key="item"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位分类" prop="identity"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.identity" placeholder="请填写类别"     ></el-input> -->
              <el-select v-model="inputForm.identity" placeholder="请填写岗位分类" style="width:100%;" >
                <el-option v-for="item in identityArr" :label="item.identity" :value="item.identity" :key="item.id"></el-option>
              </el-select>
           </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  // import {} from "../request.vue"
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          oneInstitutional: '', // 一级机构名称
          zhengLeaderNumber: '', // 正处级领导职数
          fuLeaderNumber: '', // 副处级领导职数
          oneJobStatus: '', // 一级岗位现状
          twoInstitutionalName: '', // 二级机构名称
          keLeaderNumber: '', // 科级领导职数
          twoJobStatus: '', // 二级岗位现状
          name: '', // 姓名
          gender: '', // 性别
          national: '汉', // 民族
          born: '', // 出生年月
          age: '', // 年龄
          currentPositionFile: '', // 现任职务(文件)
          currentPosition: '', // 现任职务(校内)
          identity: '', // 岗位分类
          photo: '', // 照片
          inOffice: '', // 任职时间
          inOfficeTime: '', // 任职时长
          administrativeLevel: '', // 行政级别
          asClass: '', // 任级时间
          asClassTime: '', // 任级时长
          degree: '', // 学历学位
          professional: '', // 毕业专业
          nowDegree: '', // 现在学历学位
          nowProfessional: '', // 现在毕业专业
          heightRecord: '', // 最高学历
          technicalPosition: '', // 专业技术职务
          technicalLevel: '', // 专业技术资格级别
          workforceDate: '', // 参工时间
          workYears: '', // 工龄
          inPartyDate: '', // 入党时间
          heightEducation: '', // 最高文化程度
          heightProfessionalDate: '', // 党龄
          heightGraduationSchool: '', // 最高毕业院校及所学专业
          oneEducation: '', // 第一文化程度
          oneProfessionalDate: '', // 第一毕业时间
          oneGraduationSchool: '', // 第一毕业院校及所学专业
          assessYear: '', // 考核年份
          remarks: '', // 备注信息
          workNumber: '', // 员工编号
          jobNature: '', // 岗位性质
          title: ''
        },
        stateInputForm: {
          photo: '',
          name: '',
          currentPosition: '',
          identity: '',
          unit: ''
        },
        administrativeLevelArr: [],
        identityArr: [],
        unitArr: [],
        unitFilterArr: [],
        oneInstitutionalArr: [],
        twoInstitutionalNameArr: [],
        jobNatureArr: [],
        num: 1,
        imageUrl: '',
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        picArra: [],
        technicalLevelArr: [{
          value: '正高级',
          label: '正高级'
        }, {
          value: '副高级',
          label: '副高级'
        }, {
          value: '中级',
          label: '中级'
        }, {
          value: '助理级',
          label: '助理级'
        }, {
          value: '无',
          label: '无'
        }]
      }
    },
    components: {
    },
    activated () {
     if (localStorage.getItem('loginName') === 'admin') {
       this.productCascadeDate()
     }
    },
    watch: {
      'inputForm.born': function (newVal) {
         if (newVal != null && newVal !== '') {
           var age = this.time_jisuan(newVal, 'born').split('年')
           this.inputForm.age = age[0]
         } else {
           this.inputForm.age = ''
         }
      },
      'inputForm.inOffice': function (newVal) {
        if (newVal != null && newVal !== '') {
          this.inputForm.inOfficeTime = this.time_jisuan(newVal, 'inOffice')
        } else {
          this.inputForm.inOfficeTime = ''
        }
      },
      'inputForm.asClass': function (newVal) {
        if (newVal != null && newVal !== '') {
          this.inputForm.asClassTime = this.time_jisuan(newVal, 'asClass')
        } else {
          this.inputForm.asClassTime = ''
        }
      },
     'inputForm.workforceDate': function (newVal) {
        if (newVal != null && newVal !== '') {
          this.inputForm.workYears = this.time_jisuan(newVal, 'workforceDate')
        } else {
          this.inputForm.workYears = ''
        }
      },
      'inputForm.inPartyDate': function (newVal) {
        if (newVal != null && newVal !== '') {
          var age = this.time_jisuan(newVal, 'inPartyDate').split('年')
          this.inputForm.heightProfessionalDate = age[0]
        } else {
          this.inputForm.heightProfessionalDate = ''
        }
        // this.ageDel(newVal, 'heightProfessionalDate', '入党时间')
      }
    },
    methods: {
       time_jisuan (start_time, name) {
          var nowYear = Number(new Date().getFullYear())
          var nowMonth = Number(new Date().getMonth()) + 1
          var nowDay = Number(new Date().getDate())
          var end_time = nowYear + '.' + nowMonth + '.' + nowDay
          var common_year = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
          var leap_year = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
          //验证日期格式
          // var reg = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s$/
          // var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/
          // var regExp = new RegExp(reg)
          //获取年月日
          var year_month_day_start = start_time.split('.')
          var year_month_day_end = end_time.split('.')
          //获取时间
          var beapart_year = parseInt(year_month_day_end[0]) - parseInt(year_month_day_start[0])
          //同一年
          if (beapart_year === 0) {
              var beapart_day = parseInt(year_month_day_end[2]) - parseInt(year_month_day_start[2])
              var beapart_month = parseInt(year_month_day_end[1]) - parseInt(year_month_day_start[1])
              if (beapart_month === 0) { // 同月
                if (beapart_day === 0) { // 同日
                  return 0
                } else if (beapart_day > 0) {
                  return beapart_day + '日'
                } else {
                  alert('日期填写错误，请重新填写！')
                  this.inputForm[name] = ''
                  return ''
                }
              } else if (beapart_month > 0) {
                if (beapart_day === 0) {
                   return beapart_month + '月'
                } else if (beapart_day > 0) {
                   return beapart_month + '月' + beapart_day + '日'
                } else {
                  if (parseInt(year_month_day_end[0]) % 4 === 0) {
                      beapart_day = leap_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                  } else {
                      beapart_day = common_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                  }
                  return (beapart_month - 1) + '月' + beapart_day + '日'
                }
              } else {
                alert('日期填写错误，请重新填写！')
                this.inputForm[name] = ''
                return ''
              }
          //非同一年
          } else if (beapart_year > 0) {
              //判断如果相差一年
              beapart_day = parseInt(year_month_day_end[2]) - parseInt(year_month_day_start[2])
              beapart_month = parseInt(year_month_day_end[1]) - parseInt(year_month_day_start[1])
              beapart_year = parseInt(year_month_day_end[0]) - parseInt(year_month_day_start[0])
              if (beapart_month === 0) {
                if (beapart_day === 0) {
                  return beapart_year + '年'
                } else if (beapart_day > 0) {
                  return beapart_year + '年0月' + beapart_day + '日'
                } else {
                  if (parseInt(year_month_day_end[0]) % 4 === 0) {
                      beapart_day = leap_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                  } else {
                      beapart_day = common_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                  }
                  return (beapart_year - 1) + '年11月' + beapart_day + '天'
                }
              } else if (beapart_month > 0) {
                  if (beapart_day === 0) {
                    return beapart_year + '年' + beapart_month + '月'
                  } else if (beapart_day > 0) {
                    return beapart_year + '年' + beapart_month + '月' + beapart_day + '日'
                  } else {
                    if (parseInt(year_month_day_end[0]) % 4 === 0) {
                        beapart_day = leap_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                    } else {
                        beapart_day = common_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                    }
                    return beapart_year + '年' + (beapart_month - 1) + '月' + beapart_day + '日'
                  }
              } else {
                  if (beapart_day === 0) {
                    return (beapart_year - 1) + '年' + (12 - parseInt(year_month_day_start[1]) + parseInt(year_month_day_end[1])) + '月'
                  } else if (beapart_day > 0) {
                    return (beapart_year - 1) + '年' + (12 - parseInt(year_month_day_start[1]) + parseInt(year_month_day_end[1])) + '月' + beapart_day + '天'
                  } else {
                    if (parseInt(year_month_day_end[0]) % 4 === 0) {
                        beapart_day = leap_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                    } else {
                        beapart_day = common_year[year_month_day_end[1]] - parseInt(year_month_day_start[2]) + parseInt(year_month_day_end[2])
                    }
                    return (beapart_year - 1) + '年' + (12 - parseInt(year_month_day_start[1]) + parseInt(year_month_day_end[1])) + '月' + beapart_day + '天'
                  }
              }
          } else {
            alert('日期填写错误，请重新填写！')
            this.inputForm[name] = ''
            return ''
          }
      },
      photoInit (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建图片管理`
        } else if (method === 'edit') {
          this.title = '修改图片管理'
        } else if (method === 'view') {
          this.title = '查看图片管理'
        }
        this.picArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/test/pic/testPic/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.testPic)
              this.inputForm.pic.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.picArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 岗位分类 行政级别 单位 下拉框数据请求
      productCascadeDate () {
        this.$http({
          url: '/peopleinformation/administrativelevel/peopleAdministrativeLevel/list',
          method: 'get',
          params: {
            administrativeLevel: ''
          }
        }).then(({data}) => {
          this.administrativeLevelArr = data.page.list
        })
        this.$http({
          url: '/peopleinformation/identityiformation/peopleIdentityInformation/list',
          method: 'get',
          params: {
            identity: ''
          }
        }).then(({data}) => {
          this.identityArr = data.page.list
        })
        this.$http({
          url: '/peopleinformation/organization/nameOfOrganization/treeData',
          method: 'get'
        }).then(({data}) => {
          this.oneInstitutionalArr = []
          for (let index = 0; index < data.treeData.length; index++) {
            this.oneInstitutionalArr.push(data.treeData[index])
          }
        })
        this.$http({
          url: '/peopleinformation/peoplejobnature/peopleJobNature/list',
          method: 'get'
        }).then(({data}) => {
          this.jobNatureArr = []
          for (var i in data.page.list) {
            this.jobNatureArr.push(data.page.list[i].jobNature)
          }
        })
      },
      // 搜索框下拉数据提供 二级机构名称下拉框数据请求
      searchTwoInstitutionalName (twoArr) {
        this.twoInstitutionalNameArr = []
        this.inputForm.twoInstitutionalName = ''
        for (let index = 0; index < twoArr.children.length; index++) {
           this.twoInstitutionalNameArr.push(twoArr.children[index])
        }
      },
      init (method, id) {
        // this.productCascadeDate()
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建人员基础资料`
        } else if (method === 'edit') {
          this.title = '修改人员基础资料'
        } else if (method === 'view') {
          this.title = '查看人员基础资料'
        }
        this.picArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/peopleinformation/basicdata/peopleInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.peopleInformation)
              this.stateInputForm = this.recover(this.stateInputForm, data.peopleInformation)
              this.inputForm.photo.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.picArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/peopleinformation/basicdata/peopleInformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>
    #headImg{
        text-align: right;
        vertical-align: middle;
        font-size: 14px;
        color: #606266;
        line-height: 20px;
        padding: 0;
        box-sizing: border-box;
        position: relative;
        left: 60px;
        top: 80px;
    }
    #showHead{
        height: 50px;
        width: 100px;
        padding: 10px;
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
    }
    #showHead:hover{
        border-color: #409EFF;
    }
    .avatar-uploader  {
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        width: 170px;
        margin-left: 10px;
    }
    .avatar-uploader:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 18px;
        color: #8c939d;
        width: 178px;
        height: 30px;
        line-height: 30px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
